--[[ 编码: WMS-105-02 名称: 作者: 日期:2025-1-29 函数: AfterDataObjDelete 功能: -- 删除【波次组成】【波次明细】 -- 删除入库波次计划出库的料箱等,更新入库单信息 更改记录: --]] wms_base = require ("wms_base") local O_WAVE_STATE_REQUEST = 1 -- 已经提交配货申请 local O_WAVE_STATE_DISTRIBUTION_OK = 2 -- 配货完成 local O_WAVE_STATE_RUN = 3 -- 作业中 local O_WAVE_STATE_ERR = 5 -- 错误 function AfterDataObjDelete( strLuaDEID ) local nRet, strRetInfo -- 获取 S_NO nRet, strRetInfo = mobox.getCurEditDataObjAttr( strLuaDEID, "S_WAVE_NO", "N_B_STATE","S_WH_CODE","S_AREA_CODE","N_PRE_B_STATE" ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取当前编辑属性失败! "..strRetInfo ) end local obj_attrs = json.decode( strRetInfo ) local wave_no = obj_attrs[1].value local b_state = lua.Get_NumAttrValue( obj_attrs[2].value ) local wh_code = lua.Get_StrAttrValue( obj_attrs[3].value ) local area_code = lua.Get_StrAttrValue( obj_attrs[4].value ) local per_b_state = lua.Get_NumAttrValue( obj_attrs[5].value ) local strCondition --作业中的出库波次无法删除 if ( wave_no == '' or wave_no == nil or b_state == O_WAVE_STATE_RUN ) then return end -- 如果状态是错误,需要获取错误前的状态 if ( b_state == O_WAVE_STATE_ERR ) then b_state = per_b_state end -- 1 未配货,已经提交配货申请 if ( b_state == O_WAVE_STATE_REQUEST ) then -- 配货中 -- 需要获取波次明细中的货品数量,申请释放分配量 strCondition = "S_WAVE_NO = '"..wave_no.."'" local strOrder = "N_ROW_NO" nRet, strRetInfo = mobox.queryDataObjAttr( strLuaDEID, "OW_Detail", strCondition, strOrder ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "获取【波次明细】失败! "..strRetInfo ) end if ( strRetInfo ~= '' ) then local ow_detail local retObjs = json.decode( strRetInfo ) local n local alloc_qty_change = {} -- 分配量变化 for n = 1, #retObjs do nRet, ow_detail = m3.ObjAttrStrToLuaObj( "OW_Detail", lua.table2str(retObjs[n].attrs) ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "m3.ObjAttrStrToLuaObj 失败! "..ow_detail ) end -- 生成分配量变化输入参数 local alloc_qty_info = { item_code = ow_detail.item_code, item_name = ow_detail.item_name, qty = ow_detail.qty, wh_code = wh_code, area_code = area_code } table.insert( alloc_qty_change, alloc_qty_info ) end -- 减仓库分配量处理 if ( #alloc_qty_change > 0 ) then local str_alloc_qty_change = lua.table2str( alloc_qty_change ) if ( wh_code ~= '' and wh_code ~= nil ) then -- 10 减仓库分配量 nRet, strRetInfo = wms.wms_AddWHInventoryChange(strLuaDEID, 10, str_alloc_qty_change ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_AddWHInventoryChange 失败! "..strRetInfo ) end end if ( area_code ~= '' and area_code ~= nil ) then -- 11 减库区分配量 nRet, strRetInfo = wms.wms_AddWHInventoryChange(strLuaDEID, 11, str_alloc_qty_change ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "wms_AddWHInventoryChange 失败! "..strRetInfo ) end end end end -- V4.0 MDF BY HAN 20241214 -- 和出库波次相关的出库单的状态要设置为 0 -- 未配货 local strUpdateSql = "N_B_STATE = 0, S_WAVE_NO = ''" strCondition = "S_WAVE_NO = '"..wave_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Outbound_Order", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then lua.Error( strLuaDEID, debug.getinfo(1), "更新【出库单】信息失败!"..strRetInfo ) end -- 已配货 elseif ( b_state == O_WAVE_STATE_DISTRIBUTION_OK ) then -- 配货完成需要删除配盘 strCondition = "S_BS_TYPE ='Outbound_Wave' AND S_BS_NO = '"..wave_no.."'" nRet, strRetInfo = mobox.deleteDataObject(strLuaDEID, "Distribution_CNTR", strCondition) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【配盘】失败!"..strRetInfo) end end -- 删除波次组成 local strCondition = "S_WAVE_NO = '"..wave_no.."'" nRet, strRetInfo = mobox.dbdeleteData( strLuaDEID, "OW_Compose", strCondition ) if ( nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除出库波次相关的【波次组成】失败! "..strRetInfo ) end -- 删除入库波次组成 local strCondition = "S_WAVE_NO = '"..wave_no.."'" nRet, strRetInfo = mobox.dbdeleteData(strLuaDEID, "OW_Detail", strCondition) if (nRet ~= 0) then lua.Error( strLuaDEID, debug.getinfo(1), "删除【OW_Detail】失败!"..strRetInfo) end -- 更新【出库单】中的 S_WAVE_NO,S_STATION_NO, S_OPERATOR_NAME, S_OPERATOR, N_B_STATE local strUpdateSql = "N_B_STATE = 0, S_WAVE_NO = '', S_STATION_NO ='', S_OPERATOR_NAME = '', S_OPERATOR = '', S_PICKBOX_CODE=''" local strCondition = "S_WAVE_NO = '"..wave_no.."'" nRet, strRetInfo = mobox.updateDataAttrByCondition( strLuaDEID, "Outbound_Order", strCondition, strUpdateSql ) if ( nRet ~= 0 ) then return 2, "更新【出库单】信息失败!"..strRetInfo end end